//
//  YZReportVCTableViewController.m
//  优品美妆
//
//  Created by apple on 16/4/7.
//  Copyright © 2016年 RongChunagYin. All rights reserved.
//

#import "LSReportVCTableViewController.h"
#import "LSComplaintsController.h"
#import "putDynamicDetailVC.h"

#define Main_Color [UIColor colorWithRed:247.0/255.0 green:247.0/255.0 blue:247.0/255.0 alpha:1]
#define MAIN_COLOR  [UIColor colorWithRed:0.0/255.0f green:180.0/255.0f blue:222.0/255.0f alpha:1.0f]
@interface LSReportVCTableViewController ()
@property (strong, nonatomic)NSArray *titleArr;
@end

@implementation LSReportVCTableViewController
static NSInteger _index;
#pragma mark - 初始化
-(NSArray *)titleArr{
    if (!_titleArr) {
        _titleArr = @[@"欺诈",@"色情",@"政治谣言",@"恶意营销",@"其他类"];
        
    }
    return _titleArr;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"举报";
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    self.tableView.rowHeight = 60;
    
    self.view.backgroundColor = Main_Color;
    self.tableView.backgroundColor = Main_Color;
    
    //设置返回按钮
    UIBarButtonItem *leftItem = [UIBarButtonItem itemWithTarget:self action:@selector(leftBarButtonItemClick) image:@"Back" highImage:@"Back"];
    self.navigationItem.leftBarButtonItem = leftItem;
    
}

-(void)leftBarButtonItemClick{
    
    [self.navigationController popViewControllerAnimated:YES];
    
}


#pragma mark - Table view data source



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.titleArr.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *cellStr = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellStr forIndexPath:indexPath];
    
    if (indexPath.row == 0) {
        
        cell.accessoryType=UITableViewCellAccessoryCheckmark;
        
    }
    
    cell.textLabel.text = self.titleArr[indexPath.row];
    cell.selectionStyle = 0;
    cell.textLabel.font =[UIFont systemFontOfSize:14];
    cell.tintColor = MAIN_COLOR;
    
//    UIView *view =[[UIView alloc] initWithFrame:CGRectMake(15, 40, self.view.frame.size.width, 1)];
//    view.backgroundColor =[[UIColor grayColor]colorWithAlphaComponent:0.3];
//    [cell.contentView addSubview:view];
    
//    if (indexPath.row==_index) {
//        cell.accessoryType = UITableViewCellAccessoryCheckmark;
//    }
//    else {
//        cell.accessoryType = UITableViewCellAccessoryNone;
//    }
    
    return cell;
}
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    // 取消前一个选中的，就是单选
    NSIndexPath *lastIndex = [NSIndexPath indexPathForRow:_index inSection:0];
    UITableViewCell *lastCell = [tableView cellForRowAtIndexPath:lastIndex];
    lastCell.accessoryType = UITableViewCellAccessoryNone;
    
    // 选中操作
    UITableViewCell *cell = [tableView  cellForRowAtIndexPath:indexPath];
    cell.accessoryType = UITableViewCellAccessoryCheckmark;
    
    // 保存选中的
    _index = indexPath.row;
    [tableView performSelector:@selector(deselectRowAtIndexPath:animated:) withObject:indexPath afterDelay:.5];
    
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, screenW, 30)];
    view.backgroundColor = Main_Color;
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, view.width, 20)];
    label.textColor = [UIColor grayColor];
    label.backgroundColor = Main_Color;
    
    label.font = [UIFont systemFontOfSize:12];

    label.text = @"请选择举报原因";
    [view addSubview:label];
    
    return view;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.width, 36 + 20)];
    view.backgroundColor = Main_Color;
    
    UIButton *nextBtn = [[UIButton alloc]initWithFrame:CGRectMake(10, 10, self.view.width - 20, 36)];
    [nextBtn setBackgroundColor:MAIN_COLOR];
    [nextBtn setTitle:@"下一步" forState:UIControlStateNormal];
    [nextBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    nextBtn.layer.cornerRadius = 10.f;
    nextBtn.userInteractionEnabled = YES;
    nextBtn.enabled = YES;
    [nextBtn addTarget:self action:@selector(theNextBtn) forControlEvents:UIControlEventTouchUpInside];
    
    [view addSubview:nextBtn];
    self.tableView.tableFooterView.userInteractionEnabled = YES;
    return view;
}

-(void)theNextBtn{
    LSComplaintsController * compVC = [[LSComplaintsController alloc]init];
    compVC.topStr = self.titleArr[_index];
    compVC.resId = self.resId;
    compVC.userName = self.userName;
    [self.navigationController pushViewController:compVC animated:YES];
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 36 + 20;
}

- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 30;
}
@end
